    ; blink-asm.asm - M. Shook 2009
	; for Arduino Atmega168
	; derived from
    ; LEDblink.asm - M. Covington 2006 
    ; For ATtiny13. 
	;
    ; Turns on and off PB4 and PB5
	;   Arduino digital pins 12 and 13
	; http://www.ai.uga.edu/mc/microcontrollers/avr/AVRnotebook.pdf
	
    ; .include "tn13def.inc" 
    .include "m169def.inc" 

    .def temp = R16 
    .def temp1 = R17 
    .def temp2 = R18 
	.def temp3 = R19
    .def mask = R20 

    start: ldi temp,0b00010000
           out PORTB,temp ; initialize port B 
           ser mask 
           out DDRB,mask ; port B all outputs 
    blink: 
           ; Delay 0.1 sec (1.2 MHz) 
           ldi temp1,200 ; outer loop count 
    L1:    ldi temp2,199 ; inner loop count 
	L2:	   ldi temp3,10  ; innermost loop count
    L3:    dec temp3
	       brne L3
	       dec temp2 
           brne L2 
           dec temp1 
           brne L1 
           ; Toggle PB4 and PB5, 
		   ;   Arduino digital pin 12 and 13
           ldi mask,0b00011000 
           eor temp,mask 
           out PORTB,temp 

           rjmp blink 
    ; End of program
